package com.earnings.okhttputils.utils.god;

import org.json.JSONArray;
import org.json.JSONObject;

import java.lang.reflect.Field;

/**
 * Created by Administrator on 2017/5/16 0016.
 */

public final class GodDataAnalysis {

    public Object dataAnalysis(Class<?> cls, JSONArray jsonArray) throws IllegalAccessException, InstantiationException {
        Object object = cls.newInstance();
        Field[] fields = object.getClass().getFields();

        for (int i = 0; i < fields.length; i++) {
            try {
                JSONObject jsonbject = jsonArray.getJSONObject(i);
                Field field = fields[i];
                field.setAccessible(true);
                field.set(field.getName(), jsonbject.getString(field.getName()));

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return object;
    }

}
